package com.tools.ad.manager;

import com.hm.base.android.mob.AMApplication;
import com.hm.base.android.mob.MobBeanManager;
import com.tools.ad.ADModule;
import com.tools.ad.cache.ADConfigCache;
import com.tools.ad.manager.task.ADServiceWrapper;
import com.tools.ad.manager.task.ADTaskMarkPool;
import com.tools.ad.service.imp.ADHttpService;
import com.tools.ad.service.imp.ADLocalService;
import com.tools.ad.service.imp.ADProtocolFactory;
import com.tools.ad.store.ADSharedPrefManager;
import com.tools.ad.strategy.ADStrategyManager;


/**
 * desc:
 * date: 2017/12/19 15:34
 * author: ancun
 */
public class ADBeanManager extends MobBeanManager {

    private ADModule adModule;

    public ADBeanManager(AMApplication imContext, ADModule adModule) {
        super(imContext);
        this.adModule = adModule;
    }

    @Override
    protected <T> T createBean(Class<T> clazz, String mark) {
        Object obj = null;
        if (clazz == ADSharedPrefManager.class) {
            obj = new ADSharedPrefManager(imContext);

        } else if (clazz == ADTaskMarkPool.class) {
            obj = new ADTaskMarkPool();

        } else if (clazz == ADConfigCache.class) {
            obj = new ADConfigCache(imContext);

        } else if (clazz == ADServiceWrapper.class) {
            obj = new ADServiceWrapper(imContext, getAdLocalService(), adModule);

        } else if (clazz == ADLocalService.class) {
            obj = new ADLocalService(getAdHttpService(), imContext, adModule);

        } else if (clazz == ADHttpService.class) {
            obj = new ADHttpService(imContext, new ADProtocolFactory());

        } else if (clazz == ADStrategyManager.class) {
            obj = new ADStrategyManager(imContext, adModule);

        } else if (clazz == AdSceneManager.class) {
            obj = new AdSceneManager(imContext, adModule);

        }
        return (T) obj;

    }

    public ADSharedPrefManager getADSharedPrefManager() {
        return getBean(ADSharedPrefManager.class);
    }

    /**
     * 任务池
     *
     * @return
     */
    public ADTaskMarkPool getADTaskMarkPool() {
        return getBean(ADTaskMarkPool.class);
    }

    /**
     * 任务池
     *
     * @return
     */
    public ADServiceWrapper getADServiceWrapper() {
        return getBean(ADServiceWrapper.class);
    }

    /**
     * 获取广告配置缓存
     *
     * @return
     */
    public ADConfigCache getADConfigCache() {
        return getBean(ADConfigCache.class);
    }

    /**
     * 获取广告配置管理器
     *
     * @return
     */
    public ADStrategyManager getADStrategyManager() {
        return getBean(ADStrategyManager.class);
    }

    /**
     * 本地服务
     *
     * @return
     */
    public ADLocalService getAdLocalService() {
        return getBean(ADLocalService.class);
    }

    /**
     * 网络请求服务
     *
     * @return
     */
    public ADHttpService getAdHttpService() {
        return getBean(ADHttpService.class);
    }

    /**
     * 广告加载管理
     *
     * @return
     */
    public AdSceneManager getAdSceneManager() {
        return getBean(AdSceneManager.class);
    }

}
